import Request from "./luch-request/index.js";
const BASE_API = {
	VITE_APP_API_BASEURL: "https://api-test.jinzhuangli.com",
	VITE_APP_CAS_BASE_URL: "https://static-test.jinzhuangli.com",
	VITE_APP_CAS_STATIC_BASE_URL: "https://static-test.jinzhuangli.com/staticFile/images/"
};
const http = new Request({
	baseURL: BASE_API.VITE_APP_API_BASEURL, //设置请求的url
	timeout: 30000 //设置延迟时间
});
//请求拦截器
http.interceptors.request.use(
	(config: any) => {
		// 可使用async await 做异步操作
		// const token = getStorage(TokenKey);
		config.header = {
			...config.header,
			"X-Access-Token":
				"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiIxNjk3MTM5OTIyMDQ2MzQxMTIyIiwicm5TdHIiOiJMcFE4Zm5zQjFLYXdGZE5KWnFnQmxENVRySzY4ODBuWSIsInVzZXJpZCI6IjE2OTcxMzk5MjIwNDYzNDExMjIiLCJ1c2VybmFtZSI6IjEzODAzNTc2NDc2IiwicmVhbG5hbWUiOiLmtYvor5UiLCJleHAiOjE3NTU2NzAzNzN9.I-ZfFeh-YXfSGSXTkSo2iOf9rmFKkmK8_r1PXu9Zhd8"
		};
		// #ifdef MP-WEIXIN
		config.header.platform = "pm_wechat_applet";
		// #endif

		return config;
	},
	(error) => {
		return Promise.resolve(error);
	}
);

// 响应拦截器
http.interceptors.response.use(
	(response: any) => {
		if (response.data.message == "请重新登录" || response.data.code == 401) {
			console.error(response.data);
		}
		return response;
	},
	(error) => {
		console.log(error, "error");
		//未登录时清空缓存跳转
		// if (error.statusCode == 401) {
		// 	uni.();
		// 	uni.switchTab({
		// 		url: "/pages/index/index.vue"
		// 	})
		// }
		return Promise.resolve(error);
	}
);
export { http };
